<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <!-- <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="状态" prop="status">
              <el-select v-model="queryParams.status" placeholder="状态" clearable>
                <el-option v-for="dict in xydz_authorize_status" :key="dict.value" :label="dict.label" :value="dict.value" />
              </el-select>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card> -->
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <!-- <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:dissent:export']">导出</el-button> -->
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" :search="false" @queryTable="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" border :data="dissentList">
        <el-table-column label="报告编号" align="center" prop="reportNo" width="200" />
        <el-table-column label="授权主体" align="center" prop="nickName" />
        <el-table-column label="授权码" align="center" prop="code" width="100" />
        <el-table-column label="授权次数" align="center" prop="authCount" width="90" />
        <el-table-column label="剩余次数" align="center" prop="count" width="90" />
        <el-table-column label="有效期限" align="center" prop="expiration" width="180" />
        <el-table-column label="状态" align="center" prop="status" width="80">
          <template #default="{ row }">
            <dict-tag :options="xydz_authorize_status" :value="row.status" />
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
  </div>
</template>

<script setup name="history-authorize" lang="ts">
import { getAuthList } from '@/api/xydz/history/index';
import { DissentVO } from '@/api/xydz/dissent/types.ts';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { xydz_authorize_status } = toRefs<any>(proxy?.useDict('xydz_authorize_status'));

const dissentList = ref<DissentVO[]>([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();

const state = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    createDep: undefined,
    reportId: undefined,
    field: undefined,
    evidence: undefined,
    newReport: undefined,
    status: undefined,
    params: {}
  }
});

const { queryParams } = toRefs(state);

/** 查询异议信息列表 */
const getList = async () => {
  loading.value = true;
  const res = await getAuthList(queryParams.value);
  dissentList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

onMounted(() => {
  getList();
});

//下载报告
const handleDown = (row) => {
  console.log(row);
};
</script>
